import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import eslintPlugin from 'vite-plugin-eslint'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    eslintPlugin({
      include: ['src/**/*.js', 'src/**/*.vue', 'src/*.js', 'src/*.vue']
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        // 两种方式都可以
        additionalData: '@import "@/assets/scssVar.scss";'
        // additionalData: '@use "@/assets/main.scss" as *;'
      }
    }
  },

  // 配置在打包时，保障所有css\js能被找到
  base: './',
  server: {
    host: '0.0.0.0', //允许内网访问
    port: 8080, //服务端口
    open: false, //服务启动是否自动打开
    cors: true //允许跨域
  },
  // 设置代理，根据我们项目实际情况配置
  // proxy: {
  //   '/api': {
  //     target: 'http://xxx.xxx.xxx.xxx:8000',
  //     changeOrigin: true,
  //     secure: false,
  //     rewrite: (path) => path.replace('/api/', '/')
  //   }
  // }

  //打包前先清空原有打包文件
  build: {
    emptyOutDir: true,
    terserOptions: {
      compress: {
        drop_console: true, // 打包时删除console
        drop_debugger: true, // 打包时删除 debugger
      },
      output: {
        comments: true  // 去掉注释内容
      }
    }
  },
  
  // eslint 规则
  rules: {
    "no-unused-vars": ["warn", { "vars": "all", "args": "none"/*, "ignoreRestSiblings": "^_" */}]
  }
})
